<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            width: 100px;
            height: 100px;
            background-color: red;
            cursor: pointer;
            font-size: 40px;
            text-align: center;
            line-height: 100px;
            color: aliceblue;
        }
         .box2{
            width: 100px;
            height: 100px;
            background-color: rgb(57, 67, 216);
            margin-top: 30px;
            cursor: pointer;
             cursor: pointer;
            font-size: 40px;
            text-align: center;
            line-height: 100px;
            color: aliceblue;
        }
    </style>
</head>
<body>
    <div class="box1">
          1  
    </div>
    <div class="box2">
          2
    </div>
    <script>
         let  divs=  document.querySelectorAll("div")
         divs[0].addEventListener("click",function(){  //注册事件
             alert("你好吗!")
         })
          divs[1].addEventListener("click",fn)

         function fn(){
            alert(99)
            divs[1].removeEventListener("click",fn)  //解除事件
         }
    </script>
</body>
</html>